package com.pdf.demo.util;

import com.google.gson.internal.LinkedTreeMap;
import org.apache.commons.lang3.StringUtils;

import java.io.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther:
 * @Date: 2019/12/06/9:26
 * @Description:
 */
public class RunMain {

    public static void main(String[] args) throws Exception {
        File file = new File("D:/json.txt");
        InputStream inputStream = new FileInputStream(file);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        StringBuffer json = new StringBuffer();
        String temp;
        while (!StringUtils.isEmpty((temp = bufferedReader.readLine()))) {
            json.append(temp);
        }
        String jsonStr = json.toString();
        LinkedTreeMap<String, Object> map = JsonUtil.fromJson(jsonStr);
        Object sexObj = map.get("sex");
        Object ageObj = map.get("age");
        Object widthObj = map.get("weight");
        Object heightObj = map.get("height");
        map.put("sexName", NormalRangeUtil.sexStyle(sexObj));
        map.put("weightRange", NormalRangeUtil.weightRange(heightObj));
        map.put("fatRateRange", NormalRangeUtil.fatRateRange(ageObj, sexObj));
        map.put("fatRange", NormalRangeUtil.fatRange(ageObj, sexObj, widthObj));
        map.put("waterRateRange", NormalRangeUtil.waterRateRange(sexObj));
        map.put("waterRange", NormalRangeUtil.waterRange(sexObj, widthObj));
        map.put("basalMetabolismRange", NormalRangeUtil.basalMetabolismRange(sexObj, ageObj));
        map.put("muscleRateRange", NormalRangeUtil.muscleRateRange(ageObj, sexObj));
        map.put("weightStateName", EvaluateUtil.weightEvaluate(map.get("height"), map.get("weight")));
        map.put("hwBmiStateName", EvaluateUtil.bmiEvaluate(map.get("hwBmi")));
        map.put("templatureStateName", EvaluateUtil.templatureEvaluate(map.get("templature")));
        map.put("leftEyesightStateName", EvaluateUtil.leftEyesightEvaluate(map.get("leftEyesight")));
        map.put("rightEyesightStateName", EvaluateUtil.rightEyesightEvaluate(map.get("rightEyesight")));
        map.put("pulseRateStateName", NormalRangeUtil.styleStatus(map.get("pulseRateState")));
        map.put("fatRateStateName", EvaluateUtil.fatRateEvaluate(ageObj, sexObj, map.get("fatRate")));//脂肪率
        map.put("fatStateName", EvaluateUtil.fatRateEvaluate(ageObj, sexObj, map.get("fatRate")));//脂肪量(和脂肪率相同)
        map.put("waterRateStateName", EvaluateUtil.waterRateEvaluate(sexObj, map.get("waterRate")));//水分率
        map.put("basalMetabolismStateName", EvaluateUtil.basalMetabolismEvaluate(sexObj, ageObj, map.get("basalMetabolism")));//基础代谢
        map.put("ecgRateStateName", NormalRangeUtil.styleStatus(map.get("ecgRateState")));
        map.put("muscleRateStateName", EvaluateUtil.muscleRateEvaluate(ageObj, sexObj, map.get("muscleRate")));//肌肉率
        map.put("visceralFatStateName", EvaluateUtil.visceralFatEvaluate(map.get("visceralFat")));//内脏脂肪
        map.put("pulseStateName", EvaluateUtil.pulseEvaluate(map.get("pulse")));//脉搏
        map.put("heightPressureStateName", EvaluateUtil.heightPressureEvaluate(map.get("heightPressure")));//收缩压(高压)
        map.put("lowPressureStateName", EvaluateUtil.lowPressureEvaluate(map.get("lowPressure")));//舒张压(低压)
        map.put("colorScoreState", EvaluateUtil.colorScoreEvaluate(map.get("colorScore")));//色弱检测
        map.put("bmiAdvice", NormalRangeUtil.bmiAdvice(map.get("hwBmiState")));
        map.put("fatRateAdvice", NormalRangeUtil.fatRateAdvice(map.get("fatRateState")));
        SetDataUtil.physicalResult(map);
        SetDataUtil.lineDate(map);
        SetDataUtil.physicalResult(map);
        PdfUtil.contractHandler("pdf_success_1", map, "D:/PDF/1.pdf");
        PdfUtil.contractHandler("pdf_success_2", map, "D:/PDF/2.pdf");
        SetDataUtil.setTempData(map);
        PdfUtil.contractHandler("pdf_success_3", map, "D:/PDF/3.pdf");
        PdfUtil.contractHandler("pdf_success_4", map, "D:/PDF/4.pdf");
        PdfUtil.contractHandler("pdf_success_5", map, "D:/PDF/5.pdf");
        String[] files = {"D:/PDF/1.pdf", "D:/PDF/2.pdf", "D:/PDF/3.pdf", "D:/PDF/4.pdf", "D:/PDF/5.pdf"};
        PdfUtil.mergePDF(files, "D:/PDF", "6.pdf");
    }

}
